<?php
$page_type = "A";
require_once 'header.php';

$input_client_id = $_GET["client_id"];

// Get the record that will get a default password reset and display it
$sql = "select Client_ID, Fname, Lname, AFlag, SFlag, Sid from CLIENT where Client_ID='$input_client_id'";

$result_array = execute_sql_in_oracle($sql);
$result = $result_array["flag"];
$cursor = $result_array["cursor"];

if (!$result) {
  $reset_error = 'Client ID('."<b><font color=\"black\">".$input_client_id."</font></b>".') query failed!';
  echo "'<p>'.$reset_error.'</p>'";
  echo("<br><form method=\"post\" action=\"client.php\">
       <input type=\"submit\" value=\"Go Back\">
       </form>");
}
// Try to get client information from database query result
else if (!($values = oci_fetch_array($cursor))) {
  // Record information not found
  $reset_error = 'Client ID('."<b><font color=\"black\">".$input_client_id."</font></b>".') record information not found!';
  echo "'<p>'.$reset_error.'</p>'";
  echo("<br><form method=\"post\" action=\"client.php\">
       <input type=\"submit\" value=\"Go Back\">
       </form>");
}
else {
  oci_free_statement($cursor);

  $client_id = $values[0];
  $password = "password";  // Default password used to reset all user account password
  $fname = $values[1];
  $lname = $values[2];
  $aflag = $values[3];
  $sflag = $values[4];
  $sid = $values[5];
  
  if ($aflag == '1' and $sflag == '1')
    $client_type = "Student-Admin";
  else if ($aflag == '1')
    $client_type = "Admin";
  else if ($sflag == '1') 
    $client_type = "Student";
  else
    $client_type = "";
	
  echo "<h2>Password Reset Confirmation</h2>";

  // Display the record to get a confirmation to reset the password to default system password
  echo("
    <form method=\"post\" action=\"client_reset_password_response.php\">
    Client ID: <input type=\"text\" readonly value = \"$client_id\" size=\"20\" maxlength=\"12\" name=\"client_id\"> <br />
    Password (default password): <input type=\"text\" readonly value = \"$password\" size=\"20\" maxlength=\"12\" name=\"password\">  <br />  
    SID: <input type=\"text\" readonly value = \"$sid\" size=\"20\" maxlength=\"10\" name=\"sid\"> <br />
	Client Type: <input type=\"text\" disabled value = \"$client_type\" size=\"20\" maxlength=\"30\" name=\"client_type\">  <br />  
	First Name: <input type=\"text\" disabled value = \"$fname\" size=\"20\" maxlength=\"30\" name=\"fname\">  <br />
    Last Name: <input type=\"text\" disabled value = \"$lname\" size=\"20\" maxlength=\"30\" name=\"lname\">  <br />");

  echo("
    <input type=\"submit\" value=\"Confirm password reset\">
    </form>

    <form method=\"post\" action=\"client.php\">
    <input type=\"submit\" value=\"Go Back\">
    </form>");
}
?>
</body>
</html>